#include <bits/stdc++.h>
using namespace std;

const int N = 50000+ 10010;
typedef long long ll;
ll arr[N];
int n;
//请输出 ID 之和为 7 的倍数的最大连续数量。如果不存在这样的组，则输出 0。
ll ans = 0;
ll cnt[N];
ll sum = 0;
unordered_map<ll, ll> mp{{0, -1}};
void Solve()
{
    scanf("%d", &n);
    for (ll i = 0; i < n; i++)
    {
        scanf("%lld", &arr[i]);
        sum = (sum + arr[i]) % 7;
        sum = (sum + 7) % 7;
        // printf("\nsum(%lld) = %lld\n", i, sum);

        // if (sum == 0)
        // {
        //     ans = max(ans, i + 1);
        // }
        if (mp.find(sum) != mp.end())
        {
            ans = max(ans, i - mp[sum]);
        }
        else
        {
            mp[sum] = i;
        }
    }
    printf("%lld\n", ans);
}
int main()
{
    Solve();
    return 0;
}